package com.tianqu.tms.dao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.dto.TransCheckUserDto;

public class TmsCheckUserDaoImp extends TmsDao implements TmsCheckUserDao {

	protected TmsCheckUserDaoImp() throws TmsDaoException {
		super();
	}
	
	public List<TransCheckUserDto> findCheckUser(String namePy) throws TmsDaoException{
		PreparedStatement ps = null;
		ResultSet rs = null;
		List<TransCheckUserDto> list = new ArrayList<TransCheckUserDto>();
		StringBuffer sql = new StringBuffer("SELECT ");
		sql.append(" ID, ");
		sql.append(" userId, ");
		sql.append(" realName, ");
		sql.append(" namePy ");
		sql.append(" FROM ");
		sql.append(TmsTableNames.TMS_CHECK_USER);
		sql.append(" WHERE namePy like '%").append(namePy).append("%'");
		sql.append("  order by realName  limit 30 ");
		try {
			ps = conn.prepareStatement(sql.toString());
			rs = ps.executeQuery();
			while (rs.next()) {
				TransCheckUserDto dto = new TransCheckUserDto();
				dto.setId(rs.getInt("ID"));
				dto.setUserId(rs.getString("userId"));
				dto.setRealName(rs.getString("realName"));
				dto.setNamePy(rs.getString("namePy"));
				list.add(dto);
			}
			return list;
		} catch (SQLException e) {
			throw new TmsDaoException(e.toString());

		} finally {
			super.close(rs, ps);
		}
	}

}
